<?php
$oGoods = new Goods();
$oPager = new CPagination(0);
$oPager->setCurrentPage(1);
$oPager->setPageSize(1000);
$oRowset = $oGoods->getSitemapList($oPager);

echo $oPager->getItemCount();
echo $oPager->pageCount;
//exit;

$files = array();

for($i = 1; $i <= $oPager->pageCount; $i++)
{
	ob_start();
	echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n";
	?>
	<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
		<?php foreach($oRowset as $oRow): ?>
			<url>
				<loc><?php echo $this->createAbsoluteUrl('/goods/default/view/', array('id' => $oRow->alias, 'category' => $oRow->category_alias)); ?></loc>
				<priority>1</priority>
				<changefreq>daily</changefreq>
				<lastmod><?php echo date('Y-m-d', strtotime($oRow->date_add)) ?></lastmod>
			</url>
		<?php endforeach; ?>
	</urlset>
	<?php
	$xml = ob_get_clean();
	@mkdir(PUBLIC_PATH .'/xml/', 0777, true);

	$file = '/xml/'. $i .'-sitemap.xml';
	$files[] = 'http://'. Yii::app()->params['host'] . $file;

	file_put_contents(PUBLIC_PATH . $file, $xml);
	unset($xml);
	?>

<?php
	$oPager->setCurrentPage($i+1);
	$oRowset = $oGoods->getSitemapList($oPager);
}


ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'. "\n";

foreach($files as $file)
{
?>
	<sitemap>
		<loc><?php echo $file; ?></loc>
		<lastmod><?php echo date('Y-m-d'); ?></lastmod>
	</sitemap>
<?php
}

echo '</sitemapindex>';

$xml = ob_get_clean();
file_put_contents(PUBLIC_PATH .'/sitemap.xml', $xml);

exit;
?>